#!/usr/bin/python2
# coding=utf-8

import cv2
import numpy as np
from std_msgs.msg import Header
from sensor_msgs.msg import Image
import rospy
from cv_bridge import CvBridge , CvBridgeError

capture = cv2.VideoCapture(8)
if __name__=="__main__":
    capture.open(0)
    rospy.init_node('Camera', anonymous=True) 
    image_pub=rospy.Publisher('/image_view/image_raw',
                                   Image,
                                    queue_size = 10) 

    while True:       
            ret, frame = capture.read()
            frame = cv2.flip(frame,0)   
            frame = cv2.flip(frame,1)   
       
            ros_frame = Image()
            header = Header(stamp = rospy.Time.now())
            header.frame_id = "Camera"
            ros_frame.header=header
            ros_frame.width = 640
            ros_frame.height = 480
            ros_frame.encoding = "bgr8"
            ros_frame.step = 1920
            ros_frame.data = np.array(frame).tostring() 
            image_pub.publish(ros_frame)
                  
            rate = rospy.Rate(10)  

    capture.release()
    cv2.destroyAllWindows() 





